package com.tianqu.tms.www.transfer.controller;

import com.tianqu.tms.core.base.Logger;
import com.tianqu.tms.core.base.TmsController;
import com.tianqu.tms.core.base.TxController;
import com.tianqu.tms.core.base.UserContext;
import com.tianqu.tms.core.exception.TmsException;
import com.tianqu.tms.core.exception.TransactionException;
import com.tianqu.tms.core.security.TmsUserProfile;
import com.tianqu.tms.entity.TransferAcceptedInfo;

public class SeniorSearchPrintAjaxController extends TmsController {
	private Logger logger = Logger.getLogger(SeniorSearchPrintAjaxController.class);
	@Override
	public void execute(UserContext uc) throws Exception {
		logger.debug(this.getClass().getName() + "#execute was called.");
		TxController controller = getTxController();
		try {
			controller.begin();
			TransferAcceptedInfo accept = new TransferAcceptedInfo();
			TmsUserProfile profile = uc.getUserProfile();
			String serial = (String)uc.getAttribute("serial");
			String type = (String)uc.getAttribute("type");
			uc.removeAttribute("serial");
			uc.removeAttribute("type");
			accept = accept.getAcceptInfoBySerial(serial,"");
			if("1".equals(type))
			{
				accept.setPg_printNum(accept.getPg_printNum()+1);
				accept.setPg_printUserId(profile.getUniqueId());
				accept.setUpdateUserId(profile.getUniqueId());
				accept.setSerial(serial);
				accept.updatePrintInfoBySerial(accept);
			}
			if("2".equals(type))
			{
				accept.setDb_printNum(accept.getDb_printNum()+1);
				accept.setDb_printUserId(profile.getUniqueId());
				accept.setUpdateUserId(profile.getUniqueId());
				accept.setSerial(serial);
				accept.updatePrintInfoBySerialDb(accept);
			}
			if("3".equals(type))
			{
				accept.setZy_printnum(accept.getZy_printnum()+1);
				accept.setZy_printUserId(profile.getUniqueId());
				accept.setUpdateUserId(profile.getUniqueId());
				accept.setSerial(serial);
				accept.updatePrintInfoBySerialZy(accept);
			}
			if("4".equals(type))
			{
				accept.setLc_printNum(accept.getLc_printNum()+1);
				accept.setLc_printUserId(profile.getUniqueId());
				accept.setUpdateUserId(profile.getUniqueId());
				accept.setSerial(serial);
				accept.updatePrintInfoBySerialLc(accept);				
			}
			if("5".equals(type))
			{
				accept.setGh_printnum(accept.getGh_printnum()+1);
				accept.setGh_printUserId(profile.getUniqueId());
				accept.setUpdateUserId(profile.getUniqueId());
				accept.setSerial(serial);
				accept.updatePrintInfoBySerialGh(accept);					
			}
			if("6".equals(type))
			{
				accept.setCy_printNum(accept.getCy_printNum()+1);
				accept.setCy_printUserId(profile.getUniqueId());
				accept.setUpdateUserId(profile.getUniqueId());
				accept.setSerial(serial);
				accept.updatePrintInfoBySerialCy(accept);					
			}
			
			logger.debug(this.getClass().getName() + "#execute was completed.");
			controller.commit();
		} catch (Exception e) {
			try {
				controller.rollback();
			} catch (TransactionException e1) {
				throw new TmsException(TmsException.DB_TXCRROR, e1);
			}
			// 系统异常
			if (e instanceof TmsException) {
				throw e;
			}
			throw new TmsException(TmsException.DB_TXCRROR, e);
		}
	}
}
